﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using XbsWebAPI.Application;
using XbsWebAPI.Application.SystemAdmin.Dtos;
using XbsWebAPI.Core.Repositories;
using XbsWebAPI.EntityFrameworkCore.Entities.SystemAdmin;

namespace XbsWebAPI.MainHost.Controllers
{
    [ApiController]
    [Route("api/xbs_v1/[controller]")]
    public class SystemMenuController : Controller
    {
        private readonly IMenuAppService _menuAppService;

        public SystemMenuController(IMenuAppService menuAppService)
        {
            _menuAppService = menuAppService;
        }

        ///// <summary>
        ///// 组装所有菜单列表，按父子级的关系（"identifying": 0-Select, 1-Add, 2-Edit, 3-Delete）
        ///// </summary>
        ///// <returns></returns>
        //[HttpGet, Route("[action]")]
        //public ResultDto<List<ListMenu>> CompositionMenus()
        //{
        //    var result = _menuAppService.CompositionMenus();
        //    return result;
        //}

        /// <summary>
        /// 查询所有菜单列表List（"identifying": 0-Select, 1-Add, 2-Edit, 3-Delete）
        /// </summary>
        /// <param name="menuType">菜单类型</param>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public ResultDto<List<Menu>> FindAllMenus(MenuType? menuType)
        {
            var result = _menuAppService.GetMenus(menuType);
            return result;
        }

        /// <summary>
        /// 查询单个菜单
        /// </summary>
        /// <param name="id">菜单Id</param>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public ResultDto<Menu> FindMenuById(Guid id)
        {
            var result = _menuAppService.GetMenuById(id);
            return result;
        }

        /// <summary>
        /// 新增菜单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("[action]")]
        public async Task<ResultDto<string>> AddMenu(CreateMenuDto model)
        {
            var result = await _menuAppService.CreateMenuAsync(model);
            
            return result;
        }

        /// <summary>
        /// 编辑菜单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("[action]")]
        public async Task<ResultDto<string>> EditMenu(EditMenuDto model)
        {
            var result = await _menuAppService.UpdateMenuAsync(model);

            return result;
        }

        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="id">菜单Id</param>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public async Task<ResultDto<string>> DeleteMenu(Guid id)
        {
            var result = await _menuAppService.RemoveMenuByIdAsync(id);

            return result;
        }

        //新建角色（添加菜单）
        //编辑角色（添加菜单）
        //删除角色
        //查询角色列表
        //查询单个角色

        //新增

    }
}
